import WidgetKit
import SwiftUI
import WidgetCalendarShared

struct SmallMonthProvider: IntentTimelineProvider {
    typealias Intent = AllConfigurationIntent
    
    func placeholder(in context: Context) -> LargeEntry {
        LargeEntry(date: Date())
    }
    
    func getSnapshot(for configuration: AllConfigurationIntent, in context: Context, completion: @escaping (LargeEntry) -> Void) {
        let entry = LargeEntry(date: Date(), configuration: configuration)
        completion(entry)
    }
    
    func getTimeline(for configuration: AllConfigurationIntent, in context: Context, completion: @escaping (Timeline<LargeEntry>) -> Void) {
        var currentDate = Date()
        if #available(iOSApplicationExtension 17.0, *) {
            currentDate = DateStorge.shared.date
        }
        let timeline = Timeline(entries: [LargeEntry(date: currentDate, configuration: configuration)], policy: .after(currentDate.tomorrow ?? currentDate))
        completion(timeline)
    }
}

struct ScreenProvider: TimelineProvider {
    func placeholder(in context: Context) -> ScreenEntry {
        ScreenEntry(date: Date())
    }

    func getSnapshot(in context: Context, completion: @escaping (ScreenEntry) -> Void) {
        let entry = ScreenEntry(date: Date())
        completion(entry)
    }

    func getTimeline(in context: Context, completion: @escaping (Timeline<ScreenEntry>) -> Void) {
        let currentDate = Date()
        let timeline = Timeline(entries: [ScreenEntry(date: currentDate)], policy: .after(currentDate.tomorrow ?? currentDate))
        completion(timeline)
    }
}
